//
//  SettingViewController.m
//  LimitFree
//
//  Created by lijinghua on 16/3/4.
//  Copyright © 2016年 lijinghua. All rights reserved.
//

#import "SettingViewController.h"
#import "MyCollectionViewController.h"

@interface SettingViewController ()

@end

@implementation SettingViewController

- (id)init{
    if (self = [super init]) {
        self.navigationStyle = LFNavigationBackStyle;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self customUI];
}

- (void)customUI
{
    NSArray *imageArray = @[@"account_candou",@"account_collect",@"account_comment",@"account_download",@"account_favorite",@"account_help",@"account_setting",@"account_user"];
    NSArray *titleArray = @[@"我的应用",@"我的收藏",@"我的评论",@"我的下载",@"我的关注",@"我的帮助",@"我的设置",@"我的账户"];
    //九宫格的布局
    CGFloat buttonHeight = 57;
    CGFloat buttonWidth  = 57;
    CGFloat padding = (kScreenWidth-3*57)/4.0;
    
    for(int index = 0; index < imageArray.count;index++){
        CGRect rect = CGRectMake(padding+(buttonWidth+padding)*(index%3), padding+(buttonHeight+padding)*(index/3), buttonWidth, buttonHeight);
        UIButton *button = [LimitFreeUIFactory createButton:rect title:titleArray[index] titleColor:[UIColor blackColor]];
        [button setImage:[UIImage imageNamed:imageArray[index]] forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:12];
        
        //通过设置图片的内边距移动图片的位置
        [button setImageEdgeInsets:UIEdgeInsetsMake(-40, 0, 0, 0)];
        //通过设置内边距的方式把title显示出来
        [button setTitleEdgeInsets:UIEdgeInsetsMake(40, -55, 0, 0)];
        
        button.tag = 1000+index;
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:button];
    }
}

- (void)buttonClick:(UIButton*)button{
    if (button.tag == 1001) {
        //进入我的收藏界面
        MyCollectionViewController *collectionVC = [[MyCollectionViewController  alloc]init];
        [self.navigationController pushViewController:collectionVC animated:YES];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
